package com.game.tank.loader;

import java.io.IOException;
import java.util.Properties;

public class PropertyMgr {

    private static volatile PropertyMgr propertyMgr;

    private final static Object lock = new Object();


    private PropertyMgr() {
        init();
    }

    public static PropertyMgr getInstance() {
        if (propertyMgr == null) {
            synchronized (lock) {
                if (propertyMgr == null) {
                    return new PropertyMgr();
                }
            }
        }
        return propertyMgr;
    }
    Properties properties = new Properties();

    public void init() {
        try {
            properties.load(PropertyMgr.class.getClassLoader().getResourceAsStream("config"));
        } catch (IOException e) {
            e.printStackTrace();
        }
    }


    public Object get(String key) {
        if (null == properties) return null;
        return properties.get(key);
    }

    public Integer getInt(String key) {
        Object o = get(key);
        if (null == o) return null;
        return Integer.parseInt((String) o);
    }
}
